/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.mail.domain;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.common.core.domain.DomainObject;
import info.peigen.hotpot.common.core.util.IdUtil;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.component.mail.manage.service.order.MailTemplateCreateOrder;
import jakarta.validation.constraints.Size;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

import java.util.Map;

/**
 * <b>(MailTemplate)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/22
 */
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class MailTemplate extends DomainObject {
    /** 模版Id */
    @Size(max = 24)
    @Builder.Default
    String templateId = IdUtil.id();
    /** 模版内容 */
    String              context;
    /** 模版参数 */
    Map<String, Object> templateMap;

    public static final String INVOICE_MAIL_TEMPLATE_ID = "invoiceMailTemplateId";

    public static MailTemplate create(ProcessorServiceContext context) {
        MailTemplateCreateOrder order = (MailTemplateCreateOrder) context.getOrder();
        return BeanUtil.copyProperties(order, MailTemplate.class);
    }
}
